package com.example.ass7.geometryprimitives;

/**
 * @author Meirav this class will set an object that will represent a point. the
 *         object will have to values x and y and will be able to compare itself
 *         to other points and calculate the distance between itself and another
 *         point
 */

public class Point {
    // Point's members
    private double y;
    private double x;

    /**
     * @param x
     *            receives a value to set at the point's x
     * @param y
     *            receives a value to set at the point's y
     */
    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    /**
     * @param xToSet
     *            the value it'll set as the x value
     */
    public void setX(double xToSet) {
        this.x = xToSet;
    }

    /**
     * @param yToSet
     *            the value it'll set as the y value
     */
    public void setY(double yToSet) {
        this.y = yToSet;
    }

    /**
     * @param other
     *            receives a point to calculate the distance to
     * @return distance returns the distance between this point and the other
     */
    public double distance(Point other) {

        double distance;

        if (this.compareEquals(other)) {
            distance = 0;

        } else {

            double xDistance = this.x - other.x;
            double yDistance = this.y - other.y;

            double xDistancePower = xDistance * xDistance;
            double yDistancePower = yDistance * yDistance;

            double distancePowerSum = xDistancePower + yDistancePower;

            distance = Math.sqrt(distancePowerSum);
        }

        return distance;

    }

    /**
     * @param other
     *            other
     * @return boolean
     */
    public boolean compareEquals(Point other) {
        if (this.x == other.x && this.y == other.y) {
            return true;
        }
        return false;
    }

    // Returns the x and y values of this point
    /**
     * @return this point's x
     */
    public double getX() {
        return this.x;
    }

    /**
     * @return this point's y
     */
    public double getY() {
        return this.y;
    }

    /**
     * @param d1
     *            gets a double to compare
     * @param d2
     *            and another one
     * @return toReturn returns the bigger value
     */
    public static double max(double d1, double d2) {
        double toReturn = 0;
        if (d1 > d2) {
            toReturn = d1;
        } else {
            toReturn = d2;
        }
        return toReturn;
    }

    /**
     * @param d1
     *            gets a double to compare
     * @param d2
     *            and another one
     * @return toReturn returns the smaller one
     */
    public static double min(double d1, double d2) {
        double toReturn = 0;
        if (d1 < d2) {
            toReturn = d1;
        } else {
            toReturn = d2;
        }
        return toReturn;
    }

    /**
     * @param p
     *            the point to which location the other point will be moved.
     */
    public void applyToPoint(Point p) {
        this.setX(p.getX());
        this.setY(p.getY());
    }
}
